Applies an accumulator function over a view. The specified seed value is used as the initial accumulator value.

Namespace:  C1.LiveLinq
Assembly:  C1.LiveLinq (in C1.LiveLinq.dll)

Syntax

C#
public static AggregationView<TSource, TAccumulate> LiveAggregate<TSource, TAccumulate>(
	this View<TSource> source,
	TAccumulate seed,
	Expression<Func<TAccumulate, TSource, TAccumulate>> funcAdd,
	Expression<Func<TAccumulate, TSource, TAccumulate>> funcRemove,
	Expression<Func<TAccumulate, TSource, bool>> funcRemoveDefined
)
Visual Basic
<ExtensionAttribute> _
Public Shared Function LiveAggregate(Of TSource, TAccumulate) ( _
	source As View(Of TSource), _
	seed As TAccumulate, _
	funcAdd As Expression(Of Func(Of TAccumulate, TSource, TAccumulate)), _
	funcRemove As Expression(Of Func(Of TAccumulate, TSource, TAccumulate)), _
	funcRemoveDefined As Expression(Of Func(Of TAccumulate, TSource, Boolean)) _
) As AggregationView(Of TSource, TAccumulate)

Parameters

source
Type: C1.LiveLinq.LiveViews..::..View<(Of <(<'TSource>)>)>
A view to aggregate over.
seed
Type: TAccumulate
The initial accumulator value.
funcAdd
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'TAccumulate, TSource, TAccumulate>)>)>>)>)>
An accumulator function to be invoked on each element that is added to the source view.
funcRemove
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'TAccumulate, TSource, TAccumulate>)>)>>)>)>
A function to be applied to the accumulated value and to an element to obtain the changed accumulated value, when an element is removed from the source view.
funcRemoveDefined
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'TAccumulate, TSource, Boolean>)>)>>)>)>
A function used to determine whether funcRemove must be applied when an element is removed from the source view, or the accumulated value is not affected by its removal.

Type Parameters

TSource
The type of the elements of source.
TAccumulate
The type of the accumulator value.

Return Value

A view representing the final accumulator value.

Remarks

It is possible to use standard LINQ query operator Aggregate instead of LiveAggregate. Both are "live" in the sense that they are recomputed automatically when any change occurs in the source. The difference is that Aggregate will every time loop through the entire source collection and aggregate it from scratch, whereas LiveAggregate will use a more performant algorithm, will maintain its value incrementally, processing only those source items that actually changed.

See Also